home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / qlib205.zip / QLIB.ZIP / C / FS.C < prev    next >
C/C++ Source or Header  |  1997-05-27  |  2KB  |  71 lines

  1. /****************************************
  2.   Ver 1.01 : compiled w/ qlib making it 32bit
  3.       1.01a : compiled w/ PMODE/w v1.31
  4.       1.01b : updated usage()
  5.       1.01c : all warning removed
  6.       1.01d : recompiled after major bug in QLIB fixed
  7. ****************************************/
  8.  
  9. #include <qlib.h>
  10. #include <dos.h>
  11. #include <conio.h>
  12. #include <stdio.h>
  13. #include <process.h>
  14. #include <stdlib.h>
  15.  
  16. void usage(void) {
  17.   printf("  Usage : FS infile outfile1 outfile2 [length]\n");
  18.   printf("   infile = file to split into 2\n");
  19.   printf("   outfile1 = 1st part\n");
  20.   printf("   outfile2 = 2nd part\n");
  21.   printf("   length = size of outfile1 [default=1/2 sizeof(infile)]\n");
  22.   exit(0);
  23. }
  24.  
  25. void error(byte *m){
  26.   printf("Error:");
  27.   printf(m);
  28.   exit(0);
  29. };
  30.  
  31. #define bufsiz 4096
  32.  
  33. word main(byte argc,byte **args) {
  34.   sword hi,ho1,ho2;
  35.   sdword len,toread,a,b;
  36.   byte buf[bufsiz];
  37.  
  38.   printf("File Splitter v1.01d  32bit   by:Peter Quiring\n");
  39.   if ((argc>5)||(argc<4)) usage();
  40.   hi=open(args[1],O_RDONLY|O_BINARY);
  41.   if (hi==-1) error("Opening infile");
  42.   a=filelength(hi);
  43.   if (argc==5) {
  44.     len=atoi(args[4]);
  45.     if (len>a) error("Invalid length");
  46.   } else len=(int)(a / 2);
  47.   ho1=creat(args[2],FA_ARCH);
  48.   if (ho1==-1) error("Opening outfile1");
  49.   ho2=creat(args[3],FA_ARCH);
  50.   if (ho2==-1) error("Opening outfile2");
  51.   a=0;
  52.   do{
  53.     toread = ((len-a)>bufsiz) ? bufsiz : len-a;
  54.     b=read(hi,buf,toread);
  55.     if ((b==-1)||(b!=toread)) error("Reading infile (1)");
  56.     b=write(ho1,buf,b);
  57.     if ((b!=(toread))||(b==-1)) error("Writing outfile1");
  58.     a+=b;
  59.   }while (a<len);
  60.   close(ho1);
  61.   while (!eof(hi)) {
  62.     b=read(hi,buf,bufsiz);
  63.     if ((b==-1)||(!b)) error("Reading infile (2)");
  64.     a=write(ho2,buf,b);
  65.     if ((a==-1)||(a!=b)) error("Writing outfile2");
  66.   };
  67.   close(ho2);
  68.   close(hi);
  69.   return 0;
  70. }
  71.